﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace Client
{
    class CaptureScreenShot
    {
        public static Bitmap Capture()
        {
            try
            {
                Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height,
                    PixelFormat.Format32bppArgb);
                Graphics g = Graphics.FromImage(bmp);
                g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0,
                    Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                return bmp;
            }
            catch
            {
                return null;
            }
        }

        public static byte[] ConvertBitmapToByteArray(Bitmap bmp)
        {
            MemoryStream stream = new MemoryStream();
            try
            {
                bmp.Save(stream, ImageFormat.Png);
                return stream.ToArray();
            }
            catch
            {
                return null;
            }
            finally
            {
                stream.Flush();
                stream.Close();
                stream.Dispose();
            }
        }
    }
}
